package com.bing.Impl;

import com.bing.dao.Step;
import com.bing.sina.TaoListener;
import com.bing.util.Context;
import com.bing.util.TaoBao;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Created by Administrator on 2014/6/26.
 */
public abstract class AbstrcatStep implements Step {

    private static final Logger logger = LoggerFactory.getLogger(AbstrcatStep.class);
    protected WebDriverWait wait;
    protected WebDriver driver;
    private AbstrcatStep nextStep;
    private boolean process = true;
    protected TaoListener taoListener;
    private boolean goNext = true;

    public void preStart(Context context) {
        wait = context.getWait();
        driver = context.getDriver();
        taoListener = context.getTaoListener();
    }

    public void end(Context context) {
        goNext = (boolean) context.getSetting(Context.GONEXT);
    }


    public void start(Context context) {
        preStart(context);
        if (process) {
            try {
                exec(context);
            } catch (Exception e) {
                logger.error("发生异常:", e);
                TaoBao.handleException(context, e);
            }
        }
        end(context);
        if (goNext && nextStep != null) {
            nextStep.start(context);
        }
    }

    public void setNextStep(AbstrcatStep nextStep) {
        this.nextStep = nextStep;
    }

    public void setProcess(Boolean process) {
        this.process = process;
    }
}
